home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1996 March
/
EnigmA AMIGA RUN 05 (1996)(G.R. Edizioni)(IT)[!][issue 1996-03][Skylink CD IV].iso
/
earcd
/
games1
/
sphere29.lha
/
SOIDATA
/
equations.txt
< prev
next >
Wrap
Text File
|
1995-11-29
|
17KB
|
473 lines
Here are some representations of what I tried to do mathmatically
within the game:
unit->power
GasPerPixel = ------------ * unit->throttle * player->fuel_factor * techfudge
unit->weight
GasPerDay = GasPerPixel * unit->speed
techfudge = f
if (tech < 327) f = 1.5;
else if (tech < 655) f = 1.4;
else if (tech < 1310) f = 1.32;
else if (tech < 2662) f = 1.26;
else if (tech < 4716) f = 1.22;
else if (tech < 7770) f = 1.2;
else if (tech < 11324) f = 1.19;
else if (tech < 22878) f = 1.15;
else if (tech < 32432) f = 1.1;
else if (tech < 44986) f = 1.05;
else f = 1.0;
unit->fuel
range = ---------- * unit->speed
GasPerDay
power unit->tech
speed = ------ * ------------ * unit->throttle * player->speed_factor
weight biggest_tech
if (unit has orders to move)
trip distance
PixelsPerTurn = -------------
trip duration
GasPerTurn = GasPerPixel * PixelsPerTurn
else
PixelsPerTurn = 0 but display as unit->speed
ie. max dist unit can move in 1 turn
GasPerTurn = 1 but display as GasPerPixel * PixelsPerTurn
ie. max fuel unit can use in 1 turn
____________________________________
distance = / 2 2 2
\/ (ax - bx) + (ay - by) + (az - bz)
The following source is Public Domain and yours to do with as you see fit!
C source for GROWTH FUNCTIONS:
VOID take_grow_turn(struct Person *whom) {
int i, j, maxswing, swing;
struct Planet *planet = NULL;
FLOAT intrum, holdf, tempF;
struct Star *istar = NULL;
struct Node *node = NULL;
if (!whom) return;
SetPointer(turnwindow, waitp, 16, 16, -6, 0);
relinquish_control = FALSE;
end_turn = FALSE;
node = planet_list->lh_Head;
while (node) {
planet = (struct Planet *)node;
if (planet->owner == whom) {
if (grow_depreciate) depreciate(planet);
if (planet == whom->home) {
i = 0x7FFFFFFF - planet->resource[MONEY];
if (i < whom->g_credit) {
i = whom->g_credit - i;
whom->g_credit = 0x7FFFFFFF;
planet->resource[MONEY] -= i;
}
else {
whom->g_credit += planet->resource[MONEY];
planet->resource[MONEY] = 0;
}
}
grow(planet);
if (planet->owner) {
if (planet->industry[NOW][TECH] > biggesttech) biggesttech = planet->industry[NOW][TECH];
if (Rnd(0, 0xffff) <= planet->population) {
intrum = IEEESPDiv(IEEESPFlt(planet->population),
IEEESPFlt(0xFFFF));
tempF = IEEESPDiv(IEEESPFlt(8), IEEESPFlt(9));
if (IEEESPCmp(intrum, tempF) == 1) maxswing = 0;
else {
tempF = IEEESPDiv(IEEESPFlt(7), IEEESPFlt(9));
if (IEEESPCmp(intrum, tempF) == 1) maxswing = 1;
else {
tempF = IEEESPDiv(IEEESPFlt(6), IEEESPFlt(9));
if (IEEESPCmp(intrum, tempF) == 1) maxswing = 2;
else {
tempF = IEEESPDiv(IEEESPFlt(5), IEEESPFlt(9));
if (IEEESPCmp(intrum, tempF) == 1) maxswing = 3;
else {
tempF = IEEESPDiv(IEEESPFlt(4), IEEESPFlt(9));
if (IEEESPCmp(intrum, tempF) == 1) maxswing = 4;
else {
tempF = IEEESPDiv(IEEESPFlt(3), IEEESPFlt(9));
if (IEEESPCmp(intrum, tempF) == 1) maxswing = 5;
else {
tempF = IEEESPDiv(IEEESPFlt(2), IEEESPFlt(9));
if (IEEESPCmp(intrum, tempF) == 1) maxswing = 6;
else {
tempF = IEEESPDiv(IEEESPFlt(1), IEEESPFlt(9));
if (IEEESPCmp(intrum, tempF) == 1) maxswing = 7;
else maxswing = 8;
}
}
}
}
}
}
}
swing = Rnd(0, maxswing);
if (swing) {
if ((holdf = (planet->political[POLI_TARGET] + swing)) > 16)
planet->political[POLI_TARGET] = holdf - 16;
else planet->political[POLI_TARGET] = holdf;
}
}
}
}
if (node->ln_Succ == (struct Node *)&planet_list->lh_Tail) node = NULL;
else node = node->ln_Succ;
}
for (i = 0; i < num_stars; i++) {
istar = galaxy[i];
istar->seen[WID] = FALSE;
if (reset_recon(whom, istar)) update_recon(i, WID);
for (j = 0; j < istar->number_of_planets; j++) {
planet = istar->planet[j];
planet->modified_this_turn[WID] = FALSE;
planet->seen[WID] = FALSE;
}
}
whom->condition |= DONE_TURN;
ClearPointer(turnwindow);
}/*end take_grow_turn()*/
VOID grow(struct Planet *planet) {
int bump, bumpr;
FLOAT political_factor = 0.0, social_factor = 0.0, yield, position_factor,
class_factor, avgf, recip, food, has[NOF], hasgc, mod_factor;
BOOL firstwarn, overspent;
USHORT thisdiff, homediff, diff, i, j, limiter, grow[NOI], bo,
avg = 2, asoc[13];
struct Person *whom = NULL, *person = NULL;
struct Star *this_star = planet->sun, *homestar = NULL, *astar = NULL;
struct Planet *homeplanet = NULL, *aplanet = NULL;
if (!planet->owner) return;
whom = planet->owner;
homeplanet = whom->home;
homestar = homeplanet->sun;
for (i = 0; i < NOI; i++) planet->industry[BEGIN][i] = planet->industry[NOW][i];
if (grow_soc) {
avg++;
asoc[10] = 0;
asoc[11] = 0;
asoc[12] = 0xFFFF;
for (i = 0; i < 10; i++) asoc[i] = abs(planet->social[NOW][i] - planet->social[SOCIAL_TARGET][i]);
for (i = 0; i < 10; i++) {
if (asoc[i] > asoc[10]) {
asoc[10] = asoc[i];
diff = i;
}
if (asoc[i] < asoc[12]) asoc[12] = asoc[i];
}
for (i = 0; i < 10; i++) if (i != diff) if (asoc[i] >= asoc[11]) asoc[11] = asoc[i];
social_factor = IEEESPFlt(asoc[0]);
for (i = 1; i < 13; i++) social_factor = IEEESPAdd(IEEESPFlt(asoc[i]), social_factor);
social_factor = IEEESPDiv(social_factor, IEEESPFlt(13));
social_factor = IEEESPDiv(social_factor, IEEESPFlt(0xFFFF));
}
if (grow_poli) {
avg++;
diff = abs(planet->political[NOW] - planet->political[POLI_TARGET]);
diff = abs(15 - diff);
political_factor = IEEESPMul(IEEESPFlt(diff), IEEESPFlt(diff));
political_factor = IEEESPMul(3.905, political_factor);
political_factor = IEEESPDiv(political_factor, IEEESPFlt(1000));
}
thisdiff = planet->position;
homediff = homeplanet->position;
diff = abs(thisdiff - homediff);
diff = abs(5 - diff);
if (diff != 0) {
position_factor = IEEESPFlt(diff * diff);
position_factor = IEEESPDiv(position_factor, 25);
}
else position_factor = .01;
thisdiff = this_star->class;
homediff = homestar->class;
diff = abs(thisdiff - homediff);
diff = abs(20 - diff);
if (diff != 0) {
class_factor = IEEESPFlt(diff * diff);
class_factor = IEEESPDiv(class_factor, 400);
}
else class_factor = .001;
if (planet->industry[BEGIN][HABITAT] >= planet->h_barrier) {
bump = planet->industry[BEGIN][HABITAT] / planet->h_barrier;
bumpr = planet->industry[BEGIN][HABITAT] % planet->h_barrier;
planet->environmod += bump;
if (planet->environmod > 35) planet->environmod = 35;
planet->industry[BEGIN][HABITAT] = planet->industry[NOW][HABITAT] = bumpr;
}
mod_factor = IEEESPDiv(IEEESPFlt(planet->environmod), IEEESPFlt(100));
mod_factor = IEEESPAdd(mod_factor, IEEESPFlt(1));
if (IEEESPTst(whom->food_factor)) {
food = IEEESPMul(whom->food_factor, IEEESPFlt(planet->population));
if (IEEESPCmp(IEEESPCeil(food), IEEESPFlt(planet->resource[FOOD])) == 1) {
planet->resource[FOOD] = 0;
planet->resource[EMPLOY] = 0;
planet->population = 0;
planet->industry[BEGIN][TECH] = planet->industry[NOW][TECH] = 0;
planet->industry[BEGIN][HABITAT] = planet->industry[NOW][HABITAT] = 0;
planet->environmod = 0;
astar = planet->sun;
person = planet->owner;
astar->owner[person->id] = FALSE;
for (i = 0; i < planet->sun->number_of_planets; i++) {
aplanet = astar->planet[i];
person = aplanet->owner;
if (person == planet->owner) {
astar->owner[person->id] = TRUE;
i = planet->sun->number_of_planets;
}
}
planet->owner = NULL;
planet->resource[FOOD] = 0;
if (whom->condition & COMPUTER_PLAYER) Remove(FindName(whom->planet_list, planet->node.ln_Name));
return;
}
else {
food = IEEESPSub(IEEESPFlt(planet->resource[FOOD]), food);
if (IEEESPCmp(food, IEEESPFlt(0xFFFF)) == 1) planet->resource[FOOD] = 0xFFFF;
else planet->resource[FOOD] = IEEESPFix(IEEESPCeil(food));
}
}
avgf = IEEESPAdd(political_factor, social_factor);
avgf = IEEESPAdd(avgf, class_factor);
avgf = IEEESPAdd(avgf, position_factor);
avgf = IEEESPMul(avgf, whom->luck);
avgf = IEEESPDiv(avgf, IEEESPFlt(avg));
avgf = IEEESPMul(avgf, mod_factor);
for (i = 0; i < NOF; i++) {
yield = IEEESPMul(IEEESPFlt(planet->resource[i]), whom->lose[i]);
yield = IEEESPDiv(yield, avgf);
yield = IEEESPSub(IEEESPFlt(planet->resource[i]), yield);
if (IEEESPCmp(yield, IEEESPFlt(0xFFFF)) == 1) planet->resource[i] = 0xFFFF;
else {
if (IEEESPCmp(yield, IEEESPFlt(0)) == 1) planet->resource[i] = IEEESPFix(yield);
else planet->resource[i] = 0;
}
}
yield = IEEESPMul(IEEESPFlt(planet->population), whom->birthrate);
yield = IEEESPSub(yield, IEEESPFlt(planet->population));
yield = IEEESPMul(yield, avgf);
yield = IEEESPAdd(yield, IEEESPFlt(planet->population));
if (IEEESPCmp(yield, IEEESPFlt(0xFFFF)) == 1) planet->population = 0xFFFF;
else {
if (IEEESPCmp(yield, IEEESPFlt(0)) == 1) planet->population = IEEESPFix(yield);
else {
planet->population = 0;
astar = planet->sun;
astar->owner[WID] = FALSE;
for (i = 0; i < planet->sun->number_of_planets; i++) {
aplanet = astar->planet[i];
person = aplanet->owner;
if (person == whom) {
astar->owner[WID] = TRUE;
i = planet->sun->number_of_planets;
}
}
planet->owner = NULL;
return;
}
}
yield = IEEESPMul(IEEESPFlt(planet->population), whom->workrate);
yield = IEEESPMul(yield, avgf);
yield = IEEESPAdd(yield, IEEESPFlt(planet->resource[EMPLOY]));
if (IEEESPCmp(yield, IEEESPFlt(0xFFFF)) == 1) planet->resource[EMPLOY] = 0xFFFF;
else {
if (IEEESPCmp(yield, IEEESPFlt(0)) == 1) planet->resource[EMPLOY] = IEEESPFix(yield);
else planet->resource[EMPLOY] = 0;
}
recip = avgf;
avgf = IEEESPDiv(IEEESPFlt(1), avgf);
for (i = 0; i < NOI; i++) grow[i] = planet->industry[BEGIN][i];
for (i = 0; i < NOI; i++) {
for (j = 0; j < NOI; j++) {
if (planet->grow_order[j] == i) {
bo = j;
j = NOI;
}
}
limiter = NONE;
firstwarn = TRUE;
do {
for (j = 0; j < NOF; j++) has[j] = IEEESPFlt(planet->resource[j]);
hasgc = IEEESPFlt(whom->g_credit);
overspent = FALSE;
for (j = 0; j < NOF; j++) {
if (IEEESPTst(yield = IEEESPMul(whom->grow[bo][j], IEEESPFlt(grow[bo])))) {
if (IEEESPCmp(yield, IEEESPFlt(0)) == 1) yield = IEEESPMul(yield, avgf);
else yield = IEEESPMul(yield, recip);
}
if (IEEESPTst(yield)) {
if (j == MONEY) {
if (IEEESPCmp(yield, has[j]) == 1) {
yield = IEEESPSub(yield, has[j]);
has[j] = 0;
if (IEEESPCmp(yield, hasgc) == 1) {
if (limiter == NONE) limiter = j;
j = NOF;
overspent = TRUE;
grow[bo]--;
}
else {
yield = IEEESPSub(hasgc, yield);
if (IEEESPCmp(yield, IEEESPFlt(0x7FFFFFFF)) == 1) hasgc = 0x7FFFFFFF;
else {
if (IEEESPCmp(yield, IEEESPFlt(0)) == 1) hasgc = yield;
else hasgc = 0;
}
}
}
else {
yield = IEEESPSub(has[j], yield);
if (IEEESPCmp(yield, IEEESPFlt(0xFFFF)) == 1) has[j] = 0xFFFF;
else {
if (IEEESPCmp(yield, IEEESPFlt(0)) == 1) has[j] = yield;
else has[j] = 0;
}
}
}
else {
if (IEEESPCmp(yield, has[j]) == 1) {
if (limiter == NONE) limiter = j;
j = NOF;
overspent = TRUE;
grow[bo]--;
}
else {
yield = IEEESPSub(has[j], yield);
if (IEEESPCmp(yield, IEEESPFlt(0xFFFF)) == 1) has[j] = 0xFFFF;
else {
if (IEEESPCmp(yield, IEEESPFlt(0)) == 1) has[j] = yield;
else has[j] = 0;
}
}
}
}
}
if (firstwarn) {
if (limiter != NONE) {
whom->c_planet = planet;
want_warning(whom, bo, limiter, GROW);
firstwarn = FALSE;
}
}
} while(overspent);
for (j = 0; j < NOF; j++) planet->resource[j] = (USHORT)IEEESPFix(IEEESPFloor(has[j]));
whom->g_credit = IEEESPFix(IEEESPFloor(hasgc));
}
planet->industry[NOW][OFFENSE] = planet->hasnow[OFFENSE] = grow[OFFENSE];
planet->industry[NOW][DEFENSE] = planet->hasnow[PSHIELD] = grow[DEFENSE];
}/*end grow()*/
VOID depreciate(struct Planet *planet) {
FLOAT holdf, political_factor = 0.0, social_factor = 0.0, position_factor,
avg_factor, class_factor;
USHORT thisdiff, homediff, diff, i, avg = 2, asoc[13];
struct Person *whom = NULL;
struct Star *this_star = planet->sun, *homestar = NULL;
struct Planet *homeplanet = NULL;
if (!planet->owner) return;
whom = planet->owner;
homeplanet = whom->home;
homestar = homeplanet->sun;
if (grow_soc) {
avg++;
asoc[10] = 0;
asoc[11] = 0;
asoc[12] = 0xFFFF;
for (i = 0; i < 10; i++) asoc[i] = abs(planet->social[NOW][i] -
planet->social[SOCIAL_TARGET][i]);
for (i = 0; i < 10; i++) {
if (asoc[i] > asoc[10]) {
asoc[10] = asoc[i];
diff = i;
}
if (asoc[i] < asoc[12]) asoc[12] = asoc[i];
}
for (i = 0; i < 10; i++) if (i != diff)
if (asoc[i] >= asoc[11]) asoc[11] = asoc[i];
social_factor = IEEESPFlt(asoc[0]);
for (i = 1; i < 13; i++)
social_factor = IEEESPAdd(IEEESPFlt(asoc[i]), social_factor);
social_factor = IEEESPDiv(social_factor, IEEESPFlt(13));
social_factor = IEEESPDiv(social_factor, IEEESPFlt(0xFFFF));
}
if (grow_poli) {
avg++;
diff = abs(planet->political[NOW] - planet->political[POLI_TARGET]);
diff = abs(15 - diff);
political_factor = IEEESPMul(IEEESPFlt(diff + 1), IEEESPFlt(diff + 1));
political_factor = IEEESPMul(3.905, political_factor);
political_factor = IEEESPDiv(political_factor, IEEESPFlt(1000));
}
thisdiff = planet->position;
homediff = homeplanet->position;
diff = abs(thisdiff - homediff);
diff = abs(5 - diff);
position_factor = IEEESPMul(IEEESPFlt(diff + 1), IEEESPFlt(diff + 1));
position_factor = IEEESPMul(27.777, position_factor);
position_factor = IEEESPDiv(position_factor, IEEESPFlt(1000));
thisdiff = this_star->class;
homediff = homestar->class;
diff = abs(thisdiff - homediff);
diff = abs(20 - diff);
class_factor = IEEESPMul(IEEESPFlt(diff + 1), IEEESPFlt(diff + 1));
class_factor = IEEESPMul(2.267, class_factor);
class_factor = IEEESPDiv(class_factor, IEEESPFlt(1000));
holdf = IEEESPAdd(political_factor, position_factor);
holdf = IEEESPAdd(holdf, social_factor);
holdf = IEEESPAdd(holdf, class_factor);
holdf = IEEESPMul(holdf, whom->luck);
avg_factor = IEEESPDiv(holdf, IEEESPFlt(avg));
for (i = 0; i < NOI; i++) {
holdf = IEEESPMul(avg_factor, planet->owner->depreciate[i]);
holdf = IEEESPMul(holdf, IEEESPFlt(planet->industry[NOW][i]));
if (IEEESPTst(holdf)) {
if (IEEESPCmp(holdf, IEEESPFlt(planet->industry[NOW][i])) == 1)
planet->industry[NOW][i] = 0;
else {
holdf = IEEESPSub(IEEESPFlt(planet->industry[NOW][i]), holdf);
if (IEEESPCmp(holdf, IEEESPFlt(0xFFFF)) == 1)
planet->industry[NOW][i] = 0xFFFF;
else planet->industry[NOW][i] = IEEESPFix(holdf);
}
}
}
}/*end depreciate()*/
If anyone desires C source for the other math functions feel free to
request them and I will get them your way.